package cn.itcast.mybatisplus.service;

import cn.itcast.mybatisplus.entity.User;
import cn.itcast.mybatisplus.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author piaohailin@163.com
 * @date 2021/4/1
 */
@Service
public class SampleService {

    private UserMapper userMapper;

    private UserMapperService userMapperAll;

    @Autowired
    public void setUserMapper(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    @Autowired
    public void setUserMapperAll(UserMapperService userMapperAll) {
        this.userMapperAll = userMapperAll;
    }

    public void testSelect() {
        System.out.println(("----- selectAll method test ------"));
        List<User> userList = userMapper.selectList(null);
//        userList.forEach(System.out::println);

        userMapperAll.list().forEach(System.out::println);
    }

    public void testInsert() {
        User user = new User();
        user.setName("new test");
        user.setAge(18);
        user.setEmail("test@mail.com");
        userMapper.insert(user);
    }

    public void testDelete() {
        userMapper.deleteById(1);
    }

    public void testUpdate() {
        User user = new User();
        user.setId(1L);
        user.setName("update test");
        user.setAge(180);
        user.setEmail("test@mail.com");
        userMapper.updateById(user);
    }
}